package com.igeekhome.controller.api;

import com.igeekhome.dto.OrderListDto;
import com.igeekhome.pojo.DNetwork;
import com.igeekhome.service.IOrderListService;
import com.igeekhome.service.IStaffService;
import com.igeekhome.util.ResultBean;
import com.igeekhome.util.TableResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @ClassName OrderListControllerApi
 * @Author admin(汪璇)
 * @Date 2020/1/19 19:06
 * @Description TODO
 */
@RestController
    @RequestMapping("/api/orderList")
public class OrderListControllerApi {
    @Autowired
    private IOrderListService orderListService;
    
    @Autowired
    private IStaffService staffService;
    
    @Value("${DIST_CLERK}")
    private Integer DIST_CLERK;
    
    /**
    * @Description 订单查询列表
    * @Param [session, page, limit, orderListDto]
    * @Return com.igeekhome.util.TableResultBean
    **/
    @RequestMapping("/list")
    public TableResultBean list(HttpSession session,@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer limit, OrderListDto orderListDto){
        //获取当前session中网点编号
        DNetwork network = (DNetwork)session.getAttribute("network");
    
        //将网点编号设置为条件查询network(权限)
        orderListDto.setOrderSource(network.getNetworkId().toString());
        return orderListService.orderList(page,limit,orderListDto);
    }
    
    //订单分配提供配送员dtree数据
    @RequestMapping("/staffList")
    public ResultBean staffList(HttpSession session){
        //获取当前session中网点编号
        DNetwork network = (DNetwork)session.getAttribute("network");
        
        //根据网点查询配送员
        ResultBean resultBean = staffService.selectByNetworkId(network,DIST_CLERK);
        return resultBean;
    }
    
    
    /**
    * @Description 订单分配列表
    * @Param [session, page, limit, orderListDto]
    * @Return com.igeekhome.util.TableResultBean
    **/
    @RequestMapping("/distList")
    public TableResultBean distList(HttpSession session,@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer limit, OrderListDto orderListDto){
        //获取当前session中网点编号
        DNetwork network = (DNetwork)session.getAttribute("network");
        
        //将网点编号设置为条件查询network(权限)
        orderListDto.setOrderSource(network.getNetworkId().toString());
        return orderListService.ditOrderList(page,limit,orderListDto);
    }
    
    
    /**
    * @Description 订单分配操作
    * @Param []
    * @Return com.igeekhome.util.ResultBean
    **/
    @RequestMapping("/distOrder")
    public ResultBean distOrder(Integer staffId,Integer[] ordersId){
       
        return orderListService.ditOrder(staffId,ordersId);
    }
    
    /**
    * @Description 订单签收
    * @Param [ordersId]
    * @Return com.igeekhome.util.TableResultBean
    **/
    @RequestMapping("/signList")
    public TableResultBean signList(HttpSession session,@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer limit,OrderListDto orderListDto){
        //获取当前session中网点编号
        DNetwork network = (DNetwork)session.getAttribute("network");
    
        //将网点编号设置为条件查询network(权限)
        orderListDto.setOrderSource(network.getNetworkId().toString());
        return orderListService.signList(page,limit,orderListDto);
    }
    /**
    * @Description 订单签收查询列表
    * @Param [ordersId]
    * @Return com.igeekhome.util.TableResultBean
    **/
    @RequestMapping("/sign")
    public TableResultBean sign(HttpSession session,@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer limit,OrderListDto orderListDto){
        //获取当前session中网点编号
        DNetwork network = (DNetwork)session.getAttribute("network");
    
        //将网点编号设置为条件查询network(权限)
        orderListDto.setOrderSource(network.getNetworkId().toString());
        return orderListService.sign(page,limit,orderListDto);
    }
    
    //订单签收
    @RequestMapping("/signOrder")
    public ResultBean signOrder(Integer[] ordersId){
        return orderListService.signOrder(ordersId);
    }
    
    
}
